package main

import (
	"context"
	"fmt"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"time"
)

func main() {
	option := options.Client().ApplyURI("mongodb://192.168.133.2:27017").
		SetConnectTimeout(time.Second).
		SetAuth(options.Credential{
			AuthMechanism:           "",
			AuthMechanismProperties: nil,
			AuthSource:              "test",
			Username:                "tester",
			Password:                "123456",
			PasswordSet:             false,
		})

	client, err := mongo.Connect(context.Background(), option)
	if err != nil {
		panic(err)
	}
	err = client.Ping(context.Background(), nil)
	if err != nil {
		panic(err)
	} else {
		fmt.Println("Successfully connected and pinged.")
	}

}
